home *** CD-ROM | disk | FTP | other *** search
- // ==================================================
- // CTouchMeDialog.cp
- // Copyright (C) 1996 Mizutori Tetsuya, July 4 1996.
- // ==================================================
- // All documents are pretty-printed in Geneva 10-point font.
-
- #include <LDialogBox.h>
- #include <LDragTask.h>
- #include <LStdControl.h>
- #include <LEditField.h>
- #include <LBroadcaster.h>
- #include <UDrawingState.h>
- #include <UDrawingUtils.h>
- #include <UMemoryMgr.h>
- #include <UDebugging.h>
-
- #include <PP_Messages.h>
- #include <UReanimator.h>
-
- #include "touchMeConstants.h"
- #include "CTouchMeApp.h"
- #include "CTouchMeDialog.h"
- #include "CRadioButton.h"
- #include "CDateEditField.h"
- #include "CTouchMePref.h"
- #include "UFileInfo.h"
- #include "UDateTime.h"
-
-
- #define isButtonOn( xState ) ( (xState) == Button_On )
- #define nButtonValue( xBoolean ) ( (xBoolean) ? Button_On : Button_Off )
-
-
- // --------------------------------------------------
- // ・ CreateTouchMeDialogStream [static]
- // --------------------------------------------------
-
- CTouchMeDialog *
- CTouchMeDialog::CreateTouchMeDialogStream(
- LStream *inStream )
- {
- return new CTouchMeDialog( inStream );
- }
-
-
- // --------------------------------------------------
- // ・ CTouchMeDialog(LStream *)
- // --------------------------------------------------
-
- CTouchMeDialog::CTouchMeDialog(
- LStream *inStream )
- : LDialogBox( inStream ),
- LDragAndDrop( UQDGlobals::GetCurrentPort(), this )
- {
- mModifier = false;
- mHilitePaneID = kNoPaneID;
- }
-
-
- // --------------------------------------------------
- // ・ ~CTouchMeDialog
- // --------------------------------------------------
-
- CTouchMeDialog::~CTouchMeDialog()
- {
- }
-
-
- // --------------------------------------------------
- // ・ FinishCreateSelf
- // --------------------------------------------------
-
- void
- CTouchMeDialog::FinishCreateSelf()
- {
- LDialogBox::FinishCreateSelf();
-
- UReanimator::LinkListenerToControls( this, this, rRidL_TouchMeDialog );
-
- // This DialogBox listens to myself the messages from Drag & Drop operations, etc.
- this->AddListener( this );
-
- // Add listeners of CRadioButtons to broadcaster of LStdCheckBox.
- // When the LStdCheckBox has changed, then change message will be sent to CRadioButtons.
- LStdCheckBox *theCheckBox;
- CRadioButton *theRadio;
-
- theCheckBox = (LStdCheckBox *) FindPaneByID( kTmeD_CrCheckbox );
- for ( long i = touchFlag_Current; i < touchFlag_END; i++ ) {
- theRadio = (CRadioButton *) FindPaneByID( kTmeD_CrButtonCurrent + i );
- theCheckBox->AddListener( theRadio );
- }
-
- theCheckBox = (LStdCheckBox *) FindPaneByID( kTmeD_MdCheckbox );
- for ( long i = touchFlag_Current; i < touchFlag_END; i++ ) {
- theRadio = (CRadioButton *) FindPaneByID( kTmeD_MdButtonCurrent + i );
- theCheckBox->AddListener( theRadio );
- }
-
-
- // This time, we do not apply Broadcast/Listener method to my EditField objects.
- #ifdef COMMENT
- /*
- PaneIDT theDateEditFieldList[8] = {
- kTmeD_CrTextEditDate, kTmeD_CrTextEditTime,
- kTmeD_MdTextEditDate, kTmeD_MdTextEditTime,
- kNoPaneID };
- PaneIDT iPaneID, iPaneID2;
-
- CDateEditField *theEditField, *theEditField2;
- for ( long i=0; (iPaneID=theDateEditFieldList[i]) != kNoPaneID; i++ ) {
- theEditField = (CDateEditField *) FindPaneByID( iPaneID );
- for ( long j=0; (iPaneID2=theDateEditFieldList[j]) != kNoPaneID; j++ ) {
- theEditField2 = (CDateEditField *) FindPaneByID( iPaneID2 );
- theEditField->AddListener( theEditField2 );
- }
- }
- */
- #endif // COMMENT
-
- }
-
-
- // --------------------------------------------------
- // ・ DrawSelf
- // --------------------------------------------------
- // Draw my additional custom figures in the dialog window.
- // This procedure erases the 2-pixel width region near the bound.
- // The reason is that the 2-pixel region may not be hilited properly
- // during a drag & drop because my window is colored at background.
-
- void
- CTouchMeDialog::DrawSelf()
- {
- StColorPenState theCurrentState;
- // LDialogBox::DrawSelf();
- StColorPenState::Normalize();
-
- RgnHandle theRgnH = ::NewRgn();
- RgnHandle theInRgnH = ::NewRgn();
-
- Rect theRect;
- CalcLocalFrameRect( theRect );
- ::RectRgn( theRgnH, &theRect );
- ::InsetRect( &theRect, 2, 2);
- ::RectRgn( theInRgnH, &theRect );
- ::DiffRgn( theRgnH, theInRgnH, theRgnH );
-
- ::EraseRgn( theRgnH );
-
- ::DisposeRgn( theRgnH );
- ::DisposeRgn( theInRgnH );
- }
-
-
- // --------------------------------------------------
- // ・ AttemptClose
- // --------------------------------------------------
- // Quit program like as "Cancel" button if "Close Box" was selected.
-
- void
- CTouchMeDialog::AttemptClose()
- {
- //LDialogBox::AttemptClose();
-
- BroadcastMessage( msg_TmeD_ButtonCencel, (void *) nil );
- }
-
-
- // --------------------------------------------------
- // ・ FindCommandStatus
- // --------------------------------------------------
-
- void
- CTouchMeDialog::FindCommandStatus(
- CommandT inCommand,
- Boolean& outEnabled,
- Boolean& outUsesMark,
- Char16& outMark,
- Str255 outName )
- {
- switch (inCommand) {
- case cmd_About:
- case cmd_Open:
- case cmd_Save:
- case cmd_Quit:
- outEnabled = true;
- break;
- default:
- outEnabled = false;
- break;
- }
- }
-
-
-
- // --------------------------------------------------
- // ・ ListenToMessage
- // --------------------------------------------------
-
- void
- CTouchMeDialog::ListenToMessage(
- MessageT inMessage,
- void *ioParam )
- {
- switch ( inMessage ) {
-
- case msg_TmeD_ButtonOK:
- {
- // Store the preference data to Prefs file.
- ProcessCommand( cmd_SavePrefs, ioParam );
- LDialogBox::ListenToMessage( inMessage, ioParam );
- }
- break;
-
- case msg_TmeD_ButtonCencel:
- {
- // Discard the preference data.
- ProcessCommand( cmd_SavePrefsWFrame, ioParam );
- LDialogBox::ListenToMessage( inMessage, ioParam );
- }
- break;
-
- case msg_TmeD_ButtonHelp:
- {
- // Show the help window.
- ProcessCommand( cmd_Open_HelpWindow, ioParam );
- }
- break;
-
- case msg_TmeD_Title:
- {
- // Show the About window.
- // But this does not work because 'Title' pane is not enabled now.
- ProcessCommand( cmd_About, ioParam );
- }
- break;
-
- case msg_TmeD_CrButtonNow:
- {
- // Set up creation date time EditFields to the current date time.
- unsigned long theDateTimeSecs;
- ::GetDateTime( &theDateTimeSecs );
-
- SetEdifFieldDateTime( kTmeD_CrTextEditDate, theDateTimeSecs );
- SetEdifFieldDateTime( kTmeD_CrTextEditTime, theDateTimeSecs );
-
- if ( GetValueForPaneID( kTmeD_ButtonSync ) == Button_On ) {
- SetEdifFieldDateTime( kTmeD_MdTextEditDate, theDateTimeSecs );
- SetEdifFieldDateTime( kTmeD_MdTextEditTime, theDateTimeSecs );
- }
- }
- break;
-
- case msg_TmeD_MdButtonNow:
- {
- // Set up modification date time EditFields to the current date time.
- unsigned long theDateTimeSecs;
- ::GetDateTime( &theDateTimeSecs );
-
- SetEdifFieldDateTime( kTmeD_MdTextEditDate, theDateTimeSecs );
- SetEdifFieldDateTime( kTmeD_MdTextEditTime, theDateTimeSecs );
-
- if ( GetValueForPaneID( kTmeD_ButtonSync ) == Button_On ) {
- SetEdifFieldDateTime( kTmeD_CrTextEditDate, theDateTimeSecs );
- SetEdifFieldDateTime( kTmeD_CrTextEditTime, theDateTimeSecs );
- }
- }
- break;
-
- case msg_TmeD_DroppedFile:
- {
- // Setup date time EditFields according to the date time stamp of the dropped file.
- // Parameter: FSSpec *ioParam
- FSSpec * theFSSpec = (FSSpec *) ioParam;
- unsigned long theCrDateTime = 0, theMdDateTime = 0;
- UFileInfo::GetFSSpecDateTime( *theFSSpec, theCrDateTime, theMdDateTime );
-
- SetEdifFieldDateTime( kTmeD_CrTextEditDate, theCrDateTime );
- SetEdifFieldDateTime( kTmeD_CrTextEditTime, theCrDateTime );
-
- SetEdifFieldDateTime( kTmeD_MdTextEditDate, theMdDateTime );
- SetEdifFieldDateTime( kTmeD_MdTextEditTime, theMdDateTime );
- }
- break;
-
- case msg_TmeD_DroppedFileCrDate:
- case msg_TmeD_DroppedFileCrTime:
- case msg_TmeD_DroppedFileMdDate:
- case msg_TmeD_DroppedFileMdTime:
- {
- // Setup date time EditFields separately according to the dropped file.
- FSSpec * theFSSpec = (FSSpec *) ioParam;
- unsigned long theCrDateTime = 0, theMdDateTime = 0;
- UFileInfo::GetFSSpecDateTime( *theFSSpec, theCrDateTime, theMdDateTime );
-
- switch ( inMessage ) {
- case msg_TmeD_DroppedFileCrDate:
- SetEdifFieldDateTime( kTmeD_CrTextEditDate, theCrDateTime ); break;
- case msg_TmeD_DroppedFileCrTime:
- SetEdifFieldDateTime( kTmeD_CrTextEditTime, theCrDateTime ); break;
- case msg_TmeD_DroppedFileMdDate:
- SetEdifFieldDateTime( kTmeD_MdTextEditDate, theMdDateTime ); break;
- case msg_TmeD_DroppedFileMdTime:
- SetEdifFieldDateTime( kTmeD_MdTextEditTime, theMdDateTime ); break;
- }
- }
- break;
-
- case msg_TmeD_CrCheckbox:
- case msg_TmeD_MdCheckbox:
- {
- // Do nothing here.
- }
- break;
-
- case msg_TmeD_CrButtonCurrent:
- case msg_TmeD_CrButtonDirect:
- case msg_TmeD_CrButtonFirst:
- case msg_TmeD_CrButtonSecond:
- {
- long k = inMessage - msg_TmeD_CrButtonCurrent;
- if ( GetValueForPaneID( kTmeD_ButtonSync ) == Button_On )
- if ( GetValueForPaneID( kTmeD_CrButtonCurrent + k ) == Button_On )
- SetValueForPaneID( kTmeD_MdButtonCurrent + k, Button_On );
- }
- break;
-
- case msg_TmeD_MdButtonCurrent:
- case msg_TmeD_MdButtonDirect:
- case msg_TmeD_MdButtonFirst:
- case msg_TmeD_MdButtonSecond:
- {
- long k = inMessage - msg_TmeD_MdButtonCurrent;
- if ( GetValueForPaneID( kTmeD_ButtonSync ) == Button_On )
- if ( GetValueForPaneID( kTmeD_MdButtonCurrent + k ) == Button_On )
- SetValueForPaneID( kTmeD_CrButtonCurrent + k, Button_On );
- }
- break;
-
- default:
- {
- LDialogBox::ListenToMessage( inMessage, ioParam );
- break;
- }
-
- }
- }
-
-
- // ==================================================
- // Seup Dialog
- // ==================================================
-
- // --------------------------------------------------
- // ・ GetGlobalFrameRect
- // --------------------------------------------------
-
- void
- CTouchMeDialog::GetGlobalFrameRect(
- Rect & outRect )
- {
- CalcPortFrameRect( outRect );
- PortToGlobalPoint( topLeft( outRect ) );
- PortToGlobalPoint( botRight( outRect ) );
- }
-
-
- // --------------------------------------------------
- // ・ MoveDialog
- // --------------------------------------------------
-
- void
- CTouchMeDialog::MoveDialog(
- CTouchMePref &inPref )
- {
- Rect theWindowRect;
- inPref.GetWindowRect( theWindowRect );
-
- if ( ! ::EmptyRect( &theWindowRect ) ) {
- DoSetPosition( topLeft( theWindowRect ));
- }
- }
-
-
- // --------------------------------------------------
- // ・ SetupDialog
- // --------------------------------------------------
-
- void
- CTouchMeDialog::SetupDialog(
- CTouchMePref &inPref )
- {
- Rect theWindowRect;
- inPref.GetWindowRect( theWindowRect );
-
- if ( ! ::EmptyRect( &theWindowRect ) ) {
- DoSetPosition( topLeft( theWindowRect ));
- }
-
- SetValueForPaneID( kTmeD_CrCheckbox,
- nButtonValue( inPref.GetEnabled( touchType_CreationDate ) ) );
-
- SetValueForPaneID( kTmeD_MdCheckbox,
- nButtonValue( inPref.GetEnabled( touchType_ModificationDate ) ) );
-
- SetValueForPaneID( kTmeD_ButtonSync,
- nButtonValue( inPref.GetSync() ) );
-
- // Because we're about to set the value for controls
- // we're listening to we'll turn off listening temporarily.
- // Otherwise we'll get in a tug-of-war
- // as the controls broadcast their changing values.
- StopListening();
-
- for ( long i = touchFlag_Current; i < touchFlag_END; i++ ) {
- SetValueForPaneID( kTmeD_CrButtonCurrent + i,
- nButtonValue( inPref.GetFlag( touchType_CreationDate, (ETouchFlag) i ) ) );
- }
-
- for ( long i = touchFlag_Current; i < touchFlag_END; i++ ) {
- SetValueForPaneID( kTmeD_MdButtonCurrent + i,
- nButtonValue( inPref.GetFlag( touchType_ModificationDate, (ETouchFlag) i ) ) );
- }
-
- // Start listening again.
- StartListening();
-
-
- Str255 str;
-
- inPref.GetDateString( touchType_CreationDate, str );
- SetEdifFieldText( kTmeD_CrTextEditDate, str);
-
- inPref.GetTimeString( touchType_CreationDate, str );
- SetEdifFieldText( kTmeD_CrTextEditTime, str);
-
-
- inPref.GetDateString( touchType_ModificationDate, str );
- SetEdifFieldText( kTmeD_MdTextEditDate, str);
-
- inPref.GetTimeString( touchType_ModificationDate, str );
- SetEdifFieldText( kTmeD_MdTextEditTime, str);
- }
-
-
- // --------------------------------------------------
- // ・ InspectDialog
- // --------------------------------------------------
-
- void
- CTouchMeDialog::InspectDialog(
- CTouchMePref &outPref )
- {
- Rect theWindowRect;
- GetGlobalFrameRect( theWindowRect );
- outPref.SetWindowRect( theWindowRect );
-
- outPref.SetEnabled( touchType_CreationDate,
- isButtonOn( GetValueForPaneID( kTmeD_CrCheckbox ) ) );
-
- outPref.SetEnabled( touchType_ModificationDate,
- isButtonOn( GetValueForPaneID( kTmeD_MdCheckbox ) ) );
-
- outPref.SetSync( isButtonOn( GetValueForPaneID( kTmeD_ButtonSync ) ) );
-
- for ( long i = touchFlag_Current; i < touchFlag_END; i++ ) {
- outPref.SetFlag( touchType_CreationDate, (ETouchFlag) i,
- isButtonOn( GetValueForPaneID( kTmeD_CrButtonCurrent + i ) ) );
- }
-
- for ( long i = touchFlag_Current; i < touchFlag_END; i++ ) {
- outPref.SetFlag( touchType_ModificationDate, (ETouchFlag) i,
- isButtonOn( GetValueForPaneID( kTmeD_MdButtonCurrent + i ) ) );
- }
-
-
- Str255 str;
-
- GetEdifFieldText( kTmeD_CrTextEditDate, str );
- outPref.SetDateString( touchType_CreationDate, str );
-
- GetEdifFieldText( kTmeD_CrTextEditTime, str);
- outPref.SetTimeString( touchType_CreationDate, str );
-
- GetEdifFieldText( kTmeD_MdTextEditDate, str);
- outPref.SetDateString( touchType_ModificationDate, str );
-
- GetEdifFieldText( kTmeD_MdTextEditTime, str);
- outPref.SetTimeString( touchType_ModificationDate, str );
- }
-
-
-
- // ==================================================
- // Common functions
- // ==================================================
-
- // --------------------------------------------------
- // ・ SetEdifFieldText
- // --------------------------------------------------
-
- void
- CTouchMeDialog::SetEdifFieldText(
- PaneIDT inPane,
- const Str255 inString )
- {
- ((CDateEditField *) FindPaneByID( inPane ))->SetText( inString );
- }
-
-
- // --------------------------------------------------
- // ・ GetEdifFieldText
- // --------------------------------------------------
-
- void
- CTouchMeDialog::GetEdifFieldText(
- PaneIDT inPane,
- Str255 outString )
- {
- ((CDateEditField *) FindPaneByID( inPane ))->GetText( outString );
- }
-
-
- // --------------------------------------------------
- // ・ SetEdifFieldDateTime
- // --------------------------------------------------
-
- void
- CTouchMeDialog::SetEdifFieldDateTime(
- PaneIDT inPane,
- const unsigned long inDateTimeSeconds )
- {
- ((CDateEditField *) FindPaneByID( inPane ))->SetDateTime( inDateTimeSeconds );
- }
-
-
- // end of program
-